package com.fzf.org.config;


import com.fzf.org.interceptor.AdminIdentityInterceptor;
import com.fzf.org.interceptor.JwtInterceptor;
import com.fzf.org.interceptor.UserIdentityInterceptor;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@RequiredArgsConstructor
public class BlogWebConfig implements WebMvcConfigurer {

    private final JwtInterceptor jwtInterceptor;
    private final AdminIdentityInterceptor adminIdentityInterceptor;
    private final UserIdentityInterceptor userIdentityInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(jwtInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns(
                        "/blog/user/login", "/blog/user/register", "/blog/admin/login",
                        "/blog/user/check/exist", "/blog/user/check/normal",
                        "/swagger-ui/**"
                ).order(1) ;

        registry.addInterceptor(userIdentityInterceptor)
                .addPathPatterns("/blog/blog/**")
                .addPathPatterns("/blog/draft/**")
                .addPathPatterns("/blog/user/**")
                .excludePathPatterns(
                        "/blog/user/login", "/blog/user/register",  "/blog/user/logout",
                        "/blog/user/check/exist", "/blog/user/check/normal"
                )
                .order(2) ;

        registry.addInterceptor(adminIdentityInterceptor)
                .addPathPatterns("/blog/admin/user/**")
                .order(3) ;
    }
}
